package org.ruixue.util;

/**
 * 单号生成工具类
 *
 * @author liming
 * @created 2017-9-20
 */
public final class CodeUtil {

    /**
     * 机器Id
     */
    private static final long workerId = 2L;

    /**
     * 数据中心Id
     */
    private static final long datacenterId = 1L;

    /**
     * 获取单据编码
     *
     * @authon liming
     */
    public static String getCode() {
        SnowflakeIdWorker idWorker = new SnowflakeIdWorker(workerId, datacenterId);
        long id = idWorker.nextId();
        return String.valueOf(id);
    }

    /**
     * 获取单编码
     *
     * @param workerId     机器啊Id
     * @param datacenterId 工作中心Id
     * @return
     */
    public static String getCode(long workerId, long datacenterId) {
        SnowflakeIdWorker idWorker = new SnowflakeIdWorker(workerId, datacenterId);
        long id = idWorker.nextId();
        return String.valueOf(id);
    }
}
